package com.sunday.shoufen.http;

import com.sunday.common.converter.GsonConverterFactory;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;

/**
 * Created by 刘涛 on 2017/10/17.
 */

public class ApiClient {
    private static Retrofit imAdapter;
    public final static String API_URL="http://mobile.shoufenle.com";
   public final static String WEB_URL="http://mobile.shoufenle.com/mobile/info/getInfoByCode?code=";
    public final static String  CUSTOMER_URL="https://kefu.easemob.com/webim/im.html?configId=4e70db49-e0db-4b14-b0a7-f52f44ec4bb6";
    public final static String  SHARE_URL="http://mobile.shoufenle.com/mobile/member/getSharePage?memberId=";
    private static OkHttpClient client;
    static HttpLoggingInterceptor loggingInterceptor=new HttpLoggingInterceptor();

    public static ApiService getApiAdapter(){
        if (imAdapter == null) {
            loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
            OkHttpClient.Builder builder = new OkHttpClient.Builder();
            builder.connectTimeout(30, TimeUnit.SECONDS);
            builder.readTimeout(30, TimeUnit.SECONDS);
            builder.addInterceptor(loggingInterceptor);
            builder.build();
            client = builder.build();
            imAdapter = new Retrofit.Builder()
                    .baseUrl(API_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .client(client)
                    .build();
        }
        ApiService apiService = imAdapter.create(ApiService.class);
        return apiService;
    }
}
